﻿using System;
using System.Drawing;

namespace PlantsZombies.Common.Bullet
{
    [PlantZombie(SpeciesType.Sharpshooter)]
    public unsafe class SharpshooterBullet : BulletObject
    {
        public SharpshooterBullet(ImageObject[] images, GameObject gameObject)
            : base(new Size(80, 80), images, gameObject)
        {

        }
        public override unsafe void Move(ListGameObject* ptr)
        {
            int maxWidth = _gameObject.StartX + _gameObject.CellWidth * _gameObject.UseMaxColumn;
            for (int i = 0; i < _bullets.Count; i++)
            {
                var item = _bullets[i];
                item.X += 10;
                if (item.X + BulletSize.Width / 2 >= maxWidth)
                    _bullets.RemoveAt(i);
            }
        }
        public override void Play(IntPtr hdc)
        {
            base.Play(hdc);
            if (_gameObject.CurPlayIndex == _imagesBullet.Length - 1)
                _bullets.Add(new BulletPoint
                {
                    Index = 0,
                    X = _gameObject.Location.X + (_gameObject.CellHeight - _gameObject.Size.Width) / 2,
                    Y = _gameObject.Location.Y - (_gameObject.CellHeight - BulletSize.Height) / 2,
                });
        }
    }
}
